package com.hopu.controller;


import com.hopu.pojo.Menu;
import com.hopu.pojo.R;
import com.hopu.pojo.Staff;
import com.hopu.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YwaiX
 * @since 2024-09-12
 */
@RestController
@RequestMapping("/role-menu")
public class RoleMenuController {
    @Autowired
    private RoleMenuService roleMenuService;

    /**
     * 编辑角色菜单
     * @param roleId
     * @param menuIds
     * @return
     */
    @PostMapping("/edit")
    public R editRoleMenu(int roleId, int[] menuIds) {
        roleMenuService.editRoleMenu(roleId, menuIds);
        return R.ok("修改成功！！！");
    }

    /**
     * 获取角色菜单
     * @param roleId
     * @return
     */
    @GetMapping("/getMenu")
    public R getRoleMenu(int roleId) {
        return R.ok(roleMenuService.getRoleMenu(roleId));
    }

    @GetMapping("/getStaffMenu")
    public R getMenu(Staff staff) {
        List<Menu> menuList = roleMenuService.getStaffMenuList(staff.getId());
        return R.ok(menuList);
    }
}
